import 'package:flutter/material.dart';
import 'package:flutter_smart_heating/ui/ui.dart';
import 'package:flutter_swiper_null_safety_flutter3/flutter_swiper_null_safety_flutter3.dart';

class HomeNoticeView extends StatelessWidget {
  const HomeNoticeView({super.key, this.notices = const []});
  final List<dynamic> notices;

  @override
  Widget build(BuildContext context) {
    return UiPanel(
      height: 50,
      padding: const EdgeInsets.symmetric(horizontal: 10),
      child: Row(
        children: [
          Image.asset(
            'res/images/icons/vector.png',
            height: 22,
            width: 22,
          ),
          Expanded(
              child: Container(
            margin: const EdgeInsets.symmetric(
              horizontal: 10,
              vertical: 5,
            ),
            child: notices.isEmpty
                ? const Text('暂无新消息')
                : Swiper.list(
                    list: notices,
                    scrollDirection: Axis.vertical,
                    autoplay: true,
                    builder: (context, data, index) {
                      return UiOpen(
                        url: data['url'],
                        child: Container(
                          alignment: Alignment.centerLeft,
                          child: Text(
                            '${data['title']}',
                            overflow: TextOverflow.ellipsis,
                          ),
                        ),
                      );
                    },
                  ),
          )),
          const Icon(
            Icons.arrow_forward_ios,
            size: 16,
          ),
        ],
      ),
    );
  }
}
